<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <div id="app">
        <h2>今天天气很：{{info}}</h2>
        <button @click="changeWeather">切换天气</button>
    </div>

    <script>
        Vue.config.productionTip = false

        const vm = new Vue({
            el: '#app',
            data: {
                isHot: true,
            },
            computed: {
                info() {
                    return this.isHot ? '炎热' : '凉爽'
                }
            },
            methods: {
                changeWeather() {
                    this.isHot = !this.isHot
                }
            },
            watch: {
                isHot: {
                    immediate: true,
                    handler(newValue, oldValue) {
                        console.log('isHot被修改了', newValue, oldValue)
                    }
                },
                // // 简写形式
                // isHot(newValue, oldValue) {
                //     console.log('isHot被修改了', newValue, oldValue)
                // }
            }
        })
        // vm.$watch('isHot', {
        //     immediate: true,
        //     handler(newValue, oldValue) {
        //         console.log('isHot被修改了', newValue, oldValue)
        //     }
        // })
    </script>
</body>
</html>